package com.sxpi.controller;

import com.sxpi.common.result.Result;
import com.sxpi.model.entity.Bookings;
import com.sxpi.model.page.PageResult;
import com.sxpi.model.vo.BookingListVO;
import com.sxpi.model.vo.BookingsVo;
import com.sxpi.service.BookingsService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/bookings")
public class BookingsController {
    @Resource
    private BookingsService bookingsService;

    /**
     * 提交订单
     * @param bookings
     * @return
     */
    @PostMapping("/submitBooking")
    public Result<Boolean> submitBooking(@RequestBody Bookings bookings){

        return Result.ok(bookingsService.submitBooking(bookings));
    }

    /**
     * 获取订单列表
     * @param userId
     * @param pageNo
     * @param pageSize
     * @param status
     * @return
     */
    @GetMapping("/list/{userId}")
    public Result<PageResult<BookingsVo>> getBookingList(@PathVariable Long userId,
                                                         @RequestParam(required = false, defaultValue = "1") Integer pageNo,
                                                         @RequestParam(required = false, defaultValue = "10") Integer pageSize,
                                                         @RequestParam(required = false) Integer status,
                                                         @RequestParam(required = false, defaultValue = "0") Integer isRelease) {

        return bookingsService.getBookingList(userId, pageNo, pageSize, status, isRelease);
    }

    /**
     * 获取订单详情
     * @param orders
     * @return
     */
    @GetMapping("/{orders}")
    public Result<Map<String,Object>> getBookingByOrders(@PathVariable String orders) {
        return bookingsService.getBookingByOrders(orders);
    }

    /**
     *
     * 是否发布
     *
     */
    @GetMapping("/release/{userId}")
    public Result<BookingsVo> release(@PathVariable Long userId, @RequestParam(required = false, defaultValue = "0") Integer isRelease) {
        return bookingsService.release(userId,isRelease);
    }
}
